package com.demo;

import top.jfunc.websocket.WebSocketEndpoint;

import javax.websocket.*;
import javax.websocket.server.PathParam;
import javax.websocket.server.ServerEndpoint;


/**
 * @author xiongshiyan at 2019/4/21 , contact me with email yanshixiong@126.com or phone 15208384257
 */
@ServerEndpoint("/websocket/{identifier}")
public class DemoWebSocketEndpoint extends WebSocketEndpoint{
    @OnOpen
    public void onOpen(Session session , @PathParam(IDENTIFIER) String identifier) {
        System.out.println(identifier);
        connect(identifier, session);
    }
    @OnClose
    public void onClose(Session session , @PathParam(IDENTIFIER) String identifier) {
        disconnect(identifier);
    }
    @OnMessage
    public void onMessage(String message, Session session , @PathParam(IDENTIFIER) String identifier) {
        receiveMessage(identifier , message , session);
    }

    @OnError
    public void onError(Throwable t , @PathParam(IDENTIFIER) String identifier){
        disconnect(identifier);
    }
}
